package com.ys.controller.api.outer;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.amazon.SellingPartnerAPIAA.LWAAuthorizationCredentials;
import com.amazon.SellingPartnerAPIAA.LWAException;
import com.bo.sellingpartnerapi.Fulfillmentinboundv0.model.GetLabelsResponse;
import com.ys.config.MyConfig;
import com.ys.entity.base.TbPlatform;
import com.ys.entity.business.TpAmazonShop;
import com.ys.entity.business.TsCorresLog;
import com.ys.entity.storage.TccFbaInboundApiLog;
import com.ys.enume.advanced.MarketplaceEnum;
import com.ys.mapper.business.TsCorresLogMapper;
import com.ys.mapper.storage.FbaInboundApiMapper;
import com.ys.mapper.storage.TccFbaInboundApiLogMapper;
import com.ys.util.AESUtil;
import com.ys.util.amazon.FbaInboundApiV0;
import com.ys.util.amazon.Helper;
import com.ys.util.amazon.SellerSecretsVO;
import com.ys.util.dhecp.DateUtils;
import com.ys.vo.R;
import io.swagger.client.ApiException;
import io.swagger.client.api.FbaInboundApi;
import io.swagger.client.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.threeten.bp.OffsetDateTime;
import org.threeten.bp.temporal.ChronoUnit;

import java.math.BigDecimal;
import java.util.*;


/**
 * 新头程测试api 第二套方案未知箱子数据
 */
@Controller
@RequestMapping("/api/outer/demoFXZTcTwo")
public class ApiOuterDemoFXZTcTwoController {

    @Autowired
    private FbaInboundApiMapper fbaInboundApiMapper;

    @Autowired
    private TsCorresLogMapper tsCorresLogMapper;

    @Autowired
    private TccFbaInboundApiLogMapper tccFbaInboundApiLogMapper;


    /**
     * 测试新的头程流程（根据头程计划单传值）
     */
    @RequestMapping("/test400")
    @ResponseBody
    public void test400() {
        CreateInboundPlanRequest body = new CreateInboundPlanRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'a409a386-7457-4ec4-9f32-3176ab0c13b8'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        //添加国家
        List<String> destinationMarketplaces = new ArrayList();
        destinationMarketplaces.add(jsonObject.get("marketplaceId").toString());
        body.setDestinationMarketplaces(destinationMarketplaces);

        //查询头程明细
        List<Map<String, Object>> fbaPlanOrderDetailMap = fbaInboundApiMapper.getTccFbaPlanItemHb("TCJH-250106-1005");
        //计划需要的商品信息
        List<ItemInput> items = new ArrayList();
        for (Map<String, Object> fbaPlanOrderDetail : fbaPlanOrderDetailMap) {

            ItemInput itemInput = new ItemInput();
            if ("XIXI-210131-11".equals(fbaPlanOrderDetail.get("sku").toString())){
                itemInput.setLabelOwner(LabelOwner.NONE);
            }else {
                itemInput.setLabelOwner(LabelOwner.SELLER);
            }

            itemInput.setPrepOwner(PrepOwner.NONE);
            itemInput.setQuantity(new Integer(fbaPlanOrderDetail.get("numPlanDeliver").toString()));
            itemInput.setMsku(fbaPlanOrderDetail.get("sku").toString());
            items.add(itemInput);

        }
        body.setItems(items);

        //发货地址
        AddressInput sourceAddress = new AddressInput();
        //地址1
        sourceAddress.setAddressLine1(jsonObject.get("addressLine1").toString());
        //地址2
        sourceAddress.setAddressLine2(jsonObject.get("addressLine2").toString());
        //城市
        sourceAddress.setCity(jsonObject.get("city").toString());
        //国家 默认是cn
        sourceAddress.setCountryCode("CN");
        //姓名
        sourceAddress.setName(jsonObject.get("name").toString());
        //手机
        sourceAddress.setPhoneNumber(jsonObject.get("phone").toString());
        //邮编
        sourceAddress.setPostalCode(jsonObject.get("postalCode").toString());
        //州
        sourceAddress.setStateOrProvinceCode(jsonObject.get("stateOrProvinceCode").toString());

        body.setSourceAddress(sourceAddress);
        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            CreateInboundPlanResponse inboundPlan = api.createInboundPlan(body);
            System.out.println("inboundPlan=" + inboundPlan);

            TccFbaInboundApiLog tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("createInboundPlan","",inboundPlan.getInboundPlanId(),
                    JSONArray.toJSONString(body), JSONArray.toJSONString(inboundPlan), 1);
            tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);

            R r = getInboundOperationStatusList(inboundPlan.getOperationId(),"","",api);
            if (r.getCode() != 0){
                return;
            }
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }


    /**
     * 第三步。提供方框内容信息(如有) 装箱信息
     */
    @RequestMapping("/test301")
    @ResponseBody
    public void test301() {
        SetPackingInformationRequest body = new SetPackingInformationRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'a409a386-7457-4ec4-9f32-3176ab0c13b8'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        //添加国家
        List<PackageGroupingInput> packageGroupings = new ArrayList();
        PackageGroupingInput packageGroupingInput = new PackageGroupingInput();
        //shipmentId packingGroupId只能选择一个
        packageGroupingInput.setPackingGroupId("pg42caef35-efbf-49a3-b0bd-49c644f02aea");
        List<BoxInput> boxInputs = new ArrayList<>();
        List<Map<String, Object>> fbaFbaBoxDetailMapList = fbaInboundApiMapper.getFbaFbaBoxDetail();
        for (int j = 0; j < 5; j++) {
            for (Map<String, Object> fbaFbaBoxDetail : fbaFbaBoxDetailMapList) {
                BoxInput boxInput = new BoxInput();
                //箱子信息有卖家提供的二维码提供
                boxInput.setContentInformationSource(BoxContentInformationSource.BOX_CONTENT_PROVIDED);
                //包装尺寸
                Dimensions dimensions = new Dimensions();
                dimensions.setHeight(new BigDecimal(fbaFbaBoxDetail.get("Height").toString()));
                dimensions.setLength(new BigDecimal(fbaFbaBoxDetail.get("Length").toString()));
                dimensions.setWidth(new BigDecimal(fbaFbaBoxDetail.get("Width").toString()));
                //厘米
                dimensions.setUnitOfMeasurement(UnitOfMeasurement.CM);
                boxInput.setDimensions(dimensions);

                //重量
                Weight weight = new Weight();
                weight.setUnit(UnitOfWeight.KG);
                weight.setValue(new BigDecimal(fbaFbaBoxDetail.get("Weight").toString()));
                boxInput.setWeight(weight);
                JSONArray jsonArray1 = JSONArray.parseArray(fbaFbaBoxDetail.get("ProductInfo").toString());
                boxInput.setQuantity(1);
                List<ItemInput> items = new ArrayList();
                for (int i = 0; i < jsonArray1.size(); i++) {
                    JSONObject jsonObject1 = JSONObject.parseObject(String.valueOf(jsonArray1.get(i)));
                    ItemInput itemInput = new ItemInput();
                    itemInput.setLabelOwner(LabelOwner.SELLER);
                    itemInput.setPrepOwner(PrepOwner.SELLER);
                    itemInput.setQuantity(Integer.valueOf(jsonObject1.get("numRealityDeliver").toString()));
                    itemInput.setMsku(jsonObject1.get("sku").toString());
                    items.add(itemInput);

                }
                boxInput.setItems(items);
                boxInputs.add(boxInput);
            }
        }


        packageGroupingInput.setBoxes(boxInputs);
        packageGroupings.add(packageGroupingInput);
        body.setPackageGroupings(packageGroupings);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            //不允许抛弃该数据  只能重新创建入站plan
            SetPackingInformationResponse setPackingInformationResponse = api.setPackingInformation("wfd5d243b6-ef22-4a33-99bc-b42b0243ea68", body);
            setPackingInformationResponse = setPackingInformationResponse;
            System.out.println("setPackingInformationResponse=" + setPackingInformationResponse);

            TccFbaInboundApiLog tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("setPackingInformation",null,null,
                     JSONArray.toJSONString(body), JSONArray.toJSONString(setPackingInformationResponse), 1);
            tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);

            R r = getInboundOperationStatusList(setPackingInformationResponse.getOperationId(),"","",api);
            if (r.getCode() != 0){
                return;
            }
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }


    /**
     * 第四步。为目的地履行中心生成和查看选项
     */
    @RequestMapping("/test302")
    @ResponseBody
    public void test302() {
        GenerateTransportationOptionsRequest body = new GenerateTransportationOptionsRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'a409a386-7457-4ec4-9f32-3176ab0c13b8'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        List<ShipmentTransportationConfiguration> shipmentTransportationConfigurationList = new ArrayList<>();
        ShipmentTransportationConfiguration shipmentTransportationConfiguration = new ShipmentTransportationConfiguration();
        //货件id
        shipmentTransportationConfiguration.setShipmentId("sh12afeab7-aab3-4ee9-8ab0-a00368c3228a");
        //发货日期
        WindowInput windowInput = new WindowInput();
        windowInput.setStart(OffsetDateTime.parse(DateUtils.convertDateToTDate(new Date())));
        shipmentTransportationConfiguration.setReadyToShipWindow(windowInput);

        shipmentTransportationConfigurationList.add(shipmentTransportationConfiguration);

        shipmentTransportationConfiguration = new ShipmentTransportationConfiguration();
        shipmentTransportationConfiguration.setShipmentId("sh2279533f-40eb-4d47-82ee-8b22f5de5245");
        shipmentTransportationConfiguration.setReadyToShipWindow(windowInput);
        shipmentTransportationConfigurationList.add(shipmentTransportationConfiguration);

        shipmentTransportationConfiguration = new ShipmentTransportationConfiguration();
        shipmentTransportationConfiguration.setShipmentId("shc631ca70-e4d4-421b-925a-507c3b74b300");
        shipmentTransportationConfiguration.setReadyToShipWindow(windowInput);
        shipmentTransportationConfigurationList.add(shipmentTransportationConfiguration);

        shipmentTransportationConfiguration = new ShipmentTransportationConfiguration();
        shipmentTransportationConfiguration.setShipmentId("shdd6404a7-e379-4640-ba5e-612abe67aca4");
        shipmentTransportationConfiguration.setReadyToShipWindow(windowInput);
        shipmentTransportationConfigurationList.add(shipmentTransportationConfiguration);

        shipmentTransportationConfiguration = new ShipmentTransportationConfiguration();
        shipmentTransportationConfiguration.setShipmentId("she06d5c2e-14b6-46c1-984e-01ebe487fd66");
        shipmentTransportationConfiguration.setReadyToShipWindow(windowInput);
        shipmentTransportationConfigurationList.add(shipmentTransportationConfiguration);

        body.setPlacementOptionId("pl1a8a1431-f135-436b-a5cf-eb0a750360b5");
        body.setShipmentTransportationConfigurations(shipmentTransportationConfigurationList);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
//            GenerateTransportationOptionsResponse generateTransportationOptionsResponse = api.generateTransportationOptions("wfd5d243b6-ef22-4a33-99bc-b42b0243ea68", body);
//            generateTransportationOptionsResponse = generateTransportationOptionsResponse;
//            System.out.println("generateTransportationOptionsResponse=" + generateTransportationOptionsResponse);
//            TccFbaInboundApiLog tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("generateTransportationOptions", "", "wfd5d243b6-ef22-4a33-99bc-b42b0243ea68",
//                    JSONArray.toJSONString(body), JSONArray.toJSONString(generateTransportationOptionsResponse), 1);
//            tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);

            R r = getInboundOperationStatusList("2b037510-867e-4f28-a7c2-d7726c3c729d","","",api);
            if (r.getCode() != 0){
                return;
            }

            //获取承运人
            Boolean bool = true;
            ListTransportationOptionsResponse listTransportationOptionsResponse = null;
            String paginationToken = null;
            String transportationOptionId = null;
            while (bool) {
                listTransportationOptionsResponse = api.listTransportationOptions(
                        "wfd5d243b6-ef22-4a33-99bc-b42b0243ea68",
                        20,paginationToken , "pl1a8a1431-f135-436b-a5cf-eb0a750360b5",
                        null);
                TccFbaInboundApiLog tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("listTransportationOptions", null, "pl1a8a1431-f135-436b-a5cf-eb0a750360b5",
                        "wfd5d243b6-ef22-4a33-99bc-b42b0243ea68", JSONArray.toJSONString(listTransportationOptionsResponse), 1);
                tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);
                if (listTransportationOptionsResponse.getPagination().getNextToken() == null) {
                    bool = false;
                }else {
                    paginationToken = listTransportationOptionsResponse.getPagination().getNextToken();
                }
            }

        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }


    /**
     * 交货窗口为七天期,卖方可在此期间将货物交付到目的地履行中心。该窗口用于提供在亚马逊履行中心的货物预期到达日期和时间。对于所有没有与履行中心预约时间的货物,都需要一个可用的交付窗口选项。例如,通过非伙伴承运人的所有货运都需要一个经确认的交货窗口。
     */
    @RequestMapping("/test303")
    @ResponseBody
    public void test303() {
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'a409a386-7457-4ec4-9f32-3176ab0c13b8'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            //获取放置选项
            TccFbaInboundApiLog listPlacementOptionsLog = new TccFbaInboundApiLog()
                    .setType("listPlacementOptions")
                    .setId(67L)
                    .queryFirst();

            JSONObject resultJO = JSON.parseObject(listPlacementOptionsLog.getJsonResult());
            JSONArray conditionJA = JSON.parseArray(resultJO.get("placementOptions").toString());
            for (int i = 0; i < conditionJA.size(); i++) {
                JSONObject JO = conditionJA.getJSONObject(i);
                JSONArray shipmentIds = JSON.parseArray(JO.get("shipmentIds").toString());
                if (shipmentIds.size() == 5) {
//                    //每一个货件就是一个装箱单
                    for (int j = 0; j < shipmentIds.size(); j++) {
                        String  shipmentId = shipmentIds.get(j).toString();
                        GenerateDeliveryWindowOptionsResponse generateDeliveryWindowOptionsResponse = api.generateDeliveryWindowOptions(
                                "wfd5d243b6-ef22-4a33-99bc-b42b0243ea68",
                                shipmentId);
                        System.out.println("generateDeliveryWindowOptionsResponse=" + generateDeliveryWindowOptionsResponse);
                        TccFbaInboundApiLog tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("generateDeliveryWindowOptions", "", shipmentId,
                                shipmentId, JSONArray.toJSONString(generateDeliveryWindowOptionsResponse), 1);
                        tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);
                        R r = getInboundOperationStatusList(generateDeliveryWindowOptionsResponse.getOperationId(),"","",api);
                        if (r.getCode() != 0){
                            return;
                        }

                        //选择了交付窗口 就有了对应的追踪编号
                        ListDeliveryWindowOptionsResponse listDeliveryWindowOptionsResponse = api.listDeliveryWindowOptions(
                                "wfd5d243b6-ef22-4a33-99bc-b42b0243ea68", shipmentId, null, null);
                        System.out.println("listDeliveryWindowOptionsResponse=" + listDeliveryWindowOptionsResponse);
                        tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("listDeliveryWindowOptions", "", shipmentId,
                                shipmentId, JSONArray.toJSONString(listDeliveryWindowOptionsResponse), 1);
                        tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);
                    }
                }
            }

        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }

    /**
     * 确认入站计划的放置选项。一旦确认,就不能为入站计划更改。 这一步还是下一步就会后台产生fba货件
     */
    @RequestMapping("/test304")
    @ResponseBody
    public void test304() {
        GeneratePlacementOptionsRequest body = new GeneratePlacementOptionsRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'a409a386-7457-4ec4-9f32-3176ab0c13b8'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            //只能使用一个配置placementOptionId //这时候只会有fba号 还没有追踪编号
            ConfirmPlacementOptionResponse confirmPlacementOptionResponse = api.confirmPlacementOption("wfd5d243b6-ef22-4a33-99bc-b42b0243ea68",
                    "pl1a8a1431-f135-436b-a5cf-eb0a750360b5");
            confirmPlacementOptionResponse = confirmPlacementOptionResponse;
            System.out.println("confirmPlacementOptionResponse=" + confirmPlacementOptionResponse);

            TccFbaInboundApiLog tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("confirmPlacementOption","","wfd5d243b6-ef22-4a33-99bc-b42b0243ea68",
                    "pl1a8a1431-f135-436b-a5cf-eb0a750360b5", JSONArray.toJSONString(confirmPlacementOptionResponse), 1);
            tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);

            R r = getInboundOperationStatusList(confirmPlacementOptionResponse.getOperationId(),"","",api);
            if (r.getCode() != 0){
                return;
            }

        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }


    /**
     * 在入站计划中,为所选的发货确认交货窗口选项。在使用此API之前,必须确认放置选项。一旦确认,就无法生成新的交付窗口选项,但可在货物运输结束前更新选定的交付窗口选项。该窗口用于提供货物到达仓库的预期时间。所有有计划的交通工具 要求在运输选项确认之前确认一个送货窗口
     */
    @RequestMapping("/test305")
    @ResponseBody
    public void test305() {
        GeneratePlacementOptionsRequest body = new GeneratePlacementOptionsRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'a409a386-7457-4ec4-9f32-3176ab0c13b8'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();

        TccFbaInboundApiLog listPlacementOptionsLog = new TccFbaInboundApiLog()
                .setType("listPlacementOptions")
                .setId(67L)
                .queryFirst();

        JSONObject resultJO = JSON.parseObject(listPlacementOptionsLog.getJsonResult());
        JSONArray conditionJA = JSON.parseArray(resultJO.get("placementOptions").toString());

        // 获取当前时间
        OffsetDateTime now = OffsetDateTime.now();

        // 在当前时间上加30天
        OffsetDateTime futureDate = now.plus(30, ChronoUnit.DAYS);
        OffsetDateTime futureDates = now.plus(45, ChronoUnit.DAYS);

        try {
            for (int i = 0; i < conditionJA.size(); i++) {
                JSONObject JO = conditionJA.getJSONObject(i);
                JSONArray shipmentIds = JSON.parseArray(JO.get("shipmentIds").toString());
                if (shipmentIds.size() == 5) {
//                    //每一个货件就是一个装箱单
                    for (int j = 0; j < shipmentIds.size(); j++) {
                        String shipmentId = shipmentIds.get(j).toString();
                        ListDeliveryWindowOptionsResponse listDeliveryWindowOptionsResponse = api.listDeliveryWindowOptions(
                                "wfd5d243b6-ef22-4a33-99bc-b42b0243ea68", shipmentId, null, null);
                        listDeliveryWindowOptionsResponse = listDeliveryWindowOptionsResponse;
                        for (DeliveryWindowOption deliveryWindowOption : listDeliveryWindowOptionsResponse.getDeliveryWindowOptions()){
                            boolean isAfter = deliveryWindowOption.getStartDate().isAfter(futureDate);
                            boolean isBefore = deliveryWindowOption.getEndDate().isBefore(futureDates);
                            if (isBefore && isAfter){
                                deliveryWindowOption = deliveryWindowOption;
                                ConfirmDeliveryWindowOptionsResponse confirmDeliveryWindowOptionsResponse = api.confirmDeliveryWindowOptions(
                                                "wfd5d243b6-ef22-4a33-99bc-b42b0243ea68",
                                        shipmentId,
                                        deliveryWindowOption.getDeliveryWindowOptionId());
                                confirmDeliveryWindowOptionsResponse = confirmDeliveryWindowOptionsResponse;
                                System.out.println("confirmDeliveryWindowOptionsResponse=" + confirmDeliveryWindowOptionsResponse);
                                TccFbaInboundApiLog tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("confirmDeliveryWindowOptions", "", shipmentId,
                                        deliveryWindowOption.getDeliveryWindowOptionId(), JSONArray.toJSONString(confirmDeliveryWindowOptionsResponse), 1);
                                tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);
                            }
                        }
                    }
                }
            }

        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }

    /**
     * 设置渠道方式
     */
    @RequestMapping("/test306")
    @ResponseBody
    public void test306() {
        ConfirmTransportationOptionsRequest body = new ConfirmTransportationOptionsRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'a409a386-7457-4ec4-9f32-3176ab0c13b8'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();


        List<TransportationSelection> transportationSelections = new ArrayList();
        try {
            TransportationSelection transportationSelection = new TransportationSelection();
            transportationSelection.setShipmentId("sh12afeab7-aab3-4ee9-8ab0-a00368c3228a");
            transportationSelection.setTransportationOptionId("to39a8eb86-b92d-4744-b8fd-f79db5bfa237");
            transportationSelections.add(transportationSelection);

            transportationSelection = new TransportationSelection();
            transportationSelection.setShipmentId("sh2279533f-40eb-4d47-82ee-8b22f5de5245");
            transportationSelection.setTransportationOptionId("todedea8a2-d576-41da-b89a-23ed98c2894a");
            transportationSelections.add(transportationSelection);

            transportationSelection = new TransportationSelection();
            transportationSelection.setShipmentId("shc631ca70-e4d4-421b-925a-507c3b74b300");
            transportationSelection.setTransportationOptionId("to1b3b8c53-b66e-4214-9e24-0f86584b9f6f");
            transportationSelections.add(transportationSelection);

            transportationSelection = new TransportationSelection();
            transportationSelection.setShipmentId("shdd6404a7-e379-4640-ba5e-612abe67aca4");
            transportationSelection.setTransportationOptionId("to4f47bc42-21e1-41c6-b573-07e14fffd12d");
            transportationSelections.add(transportationSelection);

            transportationSelection = new TransportationSelection();
            transportationSelection.setShipmentId("she06d5c2e-14b6-46c1-984e-01ebe487fd66");
            transportationSelection.setTransportationOptionId("toe88a48b2-8d52-4f3d-a0bb-acfa2c9b8abb");
            transportationSelections.add(transportationSelection);

            body.setTransportationSelections(transportationSelections);

            ConfirmTransportationOptionsResponse confirmTransportationOptionsResponse = api.confirmTransportationOptions(
                    "wfd5d243b6-ef22-4a33-99bc-b42b0243ea68",
                    body);

            TccFbaInboundApiLog tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("confirmTransportationOptions", "wfd5d243b6-ef22-4a33-99bc-b42b0243ea68",
                    "wfd5d243b6-ef22-4a33-99bc-b42b0243ea68",
                    JSONArray.toJSONString(body), JSONArray.toJSONString(confirmTransportationOptionsResponse), 1);
            tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);

            R r = getInboundOperationStatusList(confirmTransportationOptionsResponse.getOperationId(),"","",api);
            if (r.getCode() != 0){
                return;
            }
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }


    /**
     * 测试新的头程流程
     */
    @RequestMapping("/test100")
    @ResponseBody
    public void test100() {
        CreateInboundPlanRequest body = new CreateInboundPlanRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'a409a386-7457-4ec4-9f32-3176ab0c13b8'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        //添加国家
        List<String> destinationMarketplaces = new ArrayList();
        destinationMarketplaces.add(jsonObject.get("marketplaceId").toString());
        body.setDestinationMarketplaces(destinationMarketplaces);

        String[] types = { "VC-H62V-T64V", "8B-4D3Z-FNNM", "98-QMKU-6186", "BY-N6KU-BH5E", "P1-UZMK-0CRF"};
        //计划需要的商品信息
        List<ItemInput> items = new ArrayList();

        for (String sku :types){
            ItemInput itemInput = new ItemInput();
            itemInput.setLabelOwner(LabelOwner.SELLER);
            itemInput.setPrepOwner(PrepOwner.SELLER);
            itemInput.setQuantity(100);
            itemInput.setMsku(sku);
            items.add(itemInput);
        }

        body.setItems(items);

        //发货地址
        AddressInput sourceAddress = new AddressInput();
        //地址1
        sourceAddress.setAddressLine1(jsonObject.get("addressLine1").toString());
        //地址2
        sourceAddress.setAddressLine2(jsonObject.get("addressLine2").toString());
        //城市
        sourceAddress.setCity(jsonObject.get("city").toString());
        //国家 默认是cn
        sourceAddress.setCountryCode("CN");
        //姓名
        sourceAddress.setName(jsonObject.get("name").toString());
        //手机
        sourceAddress.setPhoneNumber(jsonObject.get("phone").toString());
        //邮编
        sourceAddress.setPostalCode(jsonObject.get("postalCode").toString());
        //州
        sourceAddress.setStateOrProvinceCode(jsonObject.get("stateOrProvinceCode").toString());

        body.setSourceAddress(sourceAddress);
        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            CreateInboundPlanResponse inboundPlan = api.createInboundPlan(body);
            System.out.println("inboundPlan=" + inboundPlan);

            TccFbaInboundApiLog tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("createInboundPlan","","",
                    JSONArray.toJSONString(body), JSONArray.toJSONString(inboundPlan), 1);
            tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);

            R r = getInboundOperationStatusList(inboundPlan.getOperationId(),"","",api);
            if (r.getCode() != 0){
                return;
            }
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }


    /**
     * 第二步。确定哪些可组合在一起
     * 这一步骤对于确定哪些物品可以包装在一起是必要的。由于不同的处理或履行中心的要求,有些物品无法包装在一起。进一步分开的项目可能有折扣。
     */
    @RequestMapping("/test101")
    @ResponseBody
    public void test101() {
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'a409a386-7457-4ec4-9f32-3176ab0c13b8'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();

        try {
            //TODO 注意事项 在欧盟,SPD的发货只有折扣选择。这些折扣选择可能包括额外要求,包括每个包件重量必须小于15公斤。
            //生成入站计划的可用包装选项。
            GeneratePackingOptionsResponse generatePackingOptionsResponse = api.generatePackingOptions("wf54773df1-f1ec-4a05-b953-1f863de2e499");
            System.out.println("generatePackingOptionsResponse="+generatePackingOptionsResponse);
            TccFbaInboundApiLog tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("generatePackingOptions",null,null,
                    JSONArray.toJSONString("wf54773df1-f1ec-4a05-b953-1f863de2e499"), JSONArray.toJSONString(generatePackingOptionsResponse), 1);
            tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);

            R r = getInboundOperationStatusList(generatePackingOptionsResponse.getOperationId(),"","",api);
            if (r.getCode() != 0){
                return;
            }

//            TODO 接下来,用 手术。包装选项包含卖方可以选择的包组集,以及有助于卖方选择这些选项的其他信息。其他信息包括与每个选项相关的收费/折扣、每个选项支持的运输方式以及每个选项的到期日
            ListPackingOptionsResponse listPackingOptionsResponse = api.listPackingOptions("wf54773df1-f1ec-4a05-b953-1f863de2e499",null,null);
            System.out.println("listPackingOptionsResponse="+listPackingOptionsResponse);
            tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("listPackingOptions",null,null,
                   "wf54773df1-f1ec-4a05-b953-1f863de2e499", JSONArray.toJSONString(listPackingOptionsResponse), 1);
            tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);


//            //第二步C。每个包装方案中的清单项目
//            ListPackingGroupItemsResponse listPackingGroupItemsResponse = api.listPackingGroupItems("wfd5d243b6-ef22-4a33-99bc-b42b0243ea68","pg42caef35-efbf-49a3-b0bd-49c644f02aea",null,null);
//            System.out.println("listPackingGroupItemsResponse="+listPackingGroupItemsResponse);
//
//            TccFbaInboundApiLog tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("listPackingGroupItems",null,null,
//                    "pg4460085d-8843-45eb-9bb8-47c5c9ca8556", JSONArray.toJSONString(listPackingGroupItemsResponse), 1);
//            tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);
////
//            //第二步。选择包装选项
//            ConfirmPackingOptionResponse confirmPackingOptionResponse = api.confirmPackingOption("wfd5d243b6-ef22-4a33-99bc-b42b0243ea68", "po8d4d50f4-89cf-40ec-81e0-8afea243c3c4");
//            System.out.println("confirmPackingOptionResponse=" + confirmPackingOptionResponse);
//            tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("confirmPackingOption",null,null,
//                    "po2ecbea10-7e07-44b3-aeaa-1e332f43e55b", JSONArray.toJSONString(confirmPackingOptionResponse), 1);
//            tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }
    }


    /**
     * 第三步。提供方框内容信息(如有) 装箱信息
     */
    @RequestMapping("/test102")
    @ResponseBody
    public void test102() {
        SetPackingInformationRequest body = new SetPackingInformationRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'a409a386-7457-4ec4-9f32-3176ab0c13b8'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        //添加国家
        List<PackageGroupingInput> packageGroupings = new ArrayList();
        PackageGroupingInput packageGroupingInput = new PackageGroupingInput();
        //shipmentId packingGroupId只能选择一个
        packageGroupingInput.setPackingGroupId("pg4460085d-8843-45eb-9bb8-47c5c9ca8556");
        List<BoxInput> boxInputs = new ArrayList<>();
        String[] weightList = { "15", "12", "14", "13"};
        int i = 0;
        for (String weightNew :  weightList){
            //查询装箱数据
            BoxInput boxInput = new BoxInput();
            //箱子信息有卖家提供的二维码提供
            boxInput.setContentInformationSource(BoxContentInformationSource.BOX_CONTENT_PROVIDED);
            //包装尺寸
            Dimensions dimensions = new Dimensions();
            dimensions.setHeight(new BigDecimal("30").add(new BigDecimal(i)));
            dimensions.setLength(new BigDecimal("50").add(new BigDecimal(i)));
            dimensions.setWidth(new BigDecimal("40").add(new BigDecimal(i)));
            //厘米
            dimensions.setUnitOfMeasurement(UnitOfMeasurement.CM);
            boxInput.setDimensions(dimensions);

            //重量
            Weight weight = new Weight();
            weight.setUnit(UnitOfWeight.KG);
            weight.setValue(new BigDecimal(weightNew));
            boxInput.setWeight(weight);
            boxInput.setQuantity(1);

            String[] types = { "VC-H62V-T64V", "8B-4D3Z-FNNM", "98-QMKU-6186", "BY-N6KU-BH5E", "P1-UZMK-0CRF"};
            //计划需要的商品信息
            List<ItemInput> items = new ArrayList();

            for (String type : types){
                ItemInput itemInput = new ItemInput();
                itemInput.setLabelOwner(LabelOwner.SELLER);
                itemInput.setPrepOwner(PrepOwner.SELLER);
                itemInput.setQuantity(25);
                itemInput.setMsku(type);
                items.add(itemInput);
//                if (i == 3){
//                    ItemInput itemInput = new ItemInput();
//                    itemInput.setQuantity(20);
//                    if (type.equals("BY-N6KU-BH5E")){
//                        itemInput.setQuantity(19);
//                    }
//                    itemInput.setLabelOwner(LabelOwner.SELLER);
//                    itemInput.setPrepOwner(PrepOwner.SELLER);
//                    itemInput.setMsku(type);
//                    items.add(itemInput);
//                }else  if (i == 4){
//                    ItemInput itemInput = new ItemInput();
//                    itemInput.setQuantity(20);
//                    if (type.equals("BY-N6KU-BH5E")){
//                        itemInput.setQuantity(21);
//                    }
//                    itemInput.setLabelOwner(LabelOwner.SELLER);
//                    itemInput.setPrepOwner(PrepOwner.SELLER);
//                    itemInput.setMsku(type);
//                    items.add(itemInput);
//                }else {
//                    ItemInput itemInput = new ItemInput();
//                    itemInput.setLabelOwner(LabelOwner.SELLER);
//                    itemInput.setPrepOwner(PrepOwner.SELLER);
//                    itemInput.setQuantity(20);
//                    itemInput.setMsku(type);
//                    items.add(itemInput);
//                }
            }

            boxInput.setItems(items);
            boxInputs.add(boxInput);

            i++;
        }


        packageGroupingInput.setBoxes(boxInputs);
        packageGroupings.add(packageGroupingInput);
        body.setPackageGroupings(packageGroupings);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            //不允许抛弃该数据  只能重新创建入站plan
            SetPackingInformationResponse setPackingInformationResponse = api.setPackingInformation("wfd5d243b6-ef22-4a33-99bc-b42b0243ea68", body);
            setPackingInformationResponse = setPackingInformationResponse;
            System.out.println("setPackingInformationResponse=" + setPackingInformationResponse);

            TccFbaInboundApiLog tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("setPackingInformation",null,null,
                   "wfd5d243b6-ef22-4a33-99bc-b42b0243ea68", JSONArray.toJSONString(setPackingInformationResponse), 1);
            tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);

            InboundOperationStatus inboundOperationStatus = api.getInboundOperationStatus(setPackingInformationResponse.getOperationId());
            inboundOperationStatus = inboundOperationStatus;
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }

    /**
     * 第四步。为目的地履行中心生成和查看选项
     */
    @RequestMapping("/test103")
    @ResponseBody
    public void test103() {
        GeneratePlacementOptionsRequest body = new GeneratePlacementOptionsRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'a409a386-7457-4ec4-9f32-3176ab0c13b8'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
//            GeneratePlacementOptionsResponse generatePlacementOptionsResponse = api.generatePlacementOptions("wfd5d243b6-ef22-4a33-99bc-b42b0243ea68",body);
//            generatePlacementOptionsResponse = generatePlacementOptionsResponse;
//            System.out.println("generatePlacementOptionsResponse="+generatePlacementOptionsResponse);
//
//            TccFbaInboundApiLog tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("generatePlacementOptions",null,null,
//                   "wfd5d243b6-ef22-4a33-99bc-b42b0243ea68", JSONArray.toJSONString(generatePlacementOptionsResponse), 1);
//            tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);

//            R r = getInboundOperationStatusList("13edb5b3-53fd-46ae-8851-df2156d6470d","","",api);
//            if (r.getCode() != 0){
//                return;
//            }

//            //TODO 这里看是否能获取到配置费 需要去核实 （获得分箱的fbaid 可以通过getShipment获取到亚马逊仓库信息，但是货件还是未经证实的）
//            ListPlacementOptionsResponse listPlacementOptionsResponse = api.listPlacementOptions("wfd5d243b6-ef22-4a33-99bc-b42b0243ea68", null, null);
//            listPlacementOptionsResponse = listPlacementOptionsResponse;
////            System.out.println("listPlacementOptionsResponse=" + listPlacementOptionsResponse);
//
//            TccFbaInboundApiLog tccFbaInboundApiLog1 = TccFbaInboundApiLog.tccFbaInboundApiLog("listPlacementOptions",null,null,
//                    "wfd5d243b6-ef22-4a33-99bc-b42b0243ea68", JSONArray.toJSONString(listPlacementOptionsResponse), 1);
//            tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog1);

            Shipment shipment = api.getShipment("wfd5d243b6-ef22-4a33-99bc-b42b0243ea68", "sh12afeab7-aab3-4ee9-8ab0-a00368c3228a");
            shipment = shipment;
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }

    /**
     * 查看每一个头程数据
     */
    @RequestMapping("/test104")
    @ResponseBody
    public void test104() {
        GeneratePlacementOptionsRequest body = new GeneratePlacementOptionsRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'a409a386-7457-4ec4-9f32-3176ab0c13b8'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            //获取放置选项
            TccFbaInboundApiLog listPlacementOptionsLog = new TccFbaInboundApiLog()
                    .setType("listPlacementOptions")
                    .setId(49L)
                    .queryFirst();
//            ListPlacementOptionsResponse listPlacementOptionsResponse  = JSON.parseObject(listPlacementOptionsLog.getJsonResult(), ListPlacementOptionsResponse.class);

            JSONObject resultJO = JSON.parseObject(listPlacementOptionsLog.getJsonResult());
            JSONArray conditionJA = JSON.parseArray(resultJO.get("placementOptions").toString());
            for (int i = 0; i < conditionJA.size(); i++) {
                JSONObject JO = conditionJA.getJSONObject(i);
                JSONArray shipmentIds = JSON.parseArray(JO.get("shipmentIds").toString());
                shipmentIds = shipmentIds;
                if (shipmentIds.size() == 5) {
//                    //每一个货件就是一个装箱单
                    for (int j = 0; j < shipmentIds.size(); j++) {
                        String  shipmentId = shipmentIds.get(j).toString();
                        Shipment shipment = api.getShipment("wfd5d243b6-ef22-4a33-99bc-b42b0243ea68", shipmentId);
                        TccFbaInboundApiLog tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("getShipment", shipmentId, null,
                                shipmentId, JSONArray.toJSONString(shipment), 1);
                        tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);
                        System.out.println(shipment);
                        ListShipmentItemsResponse listShipmentItemsResponse = api.listShipmentItems("wfd5d243b6-ef22-4a33-99bc-b42b0243ea68", shipmentId, null, null);

                        tccFbaInboundApiLog = TccFbaInboundApiLog.tccFbaInboundApiLog("listShipmentItems", shipmentId, null,
                                shipmentId, JSONArray.toJSONString(listShipmentItemsResponse), 1);
                        tccFbaInboundApiLogMapper.insert(tccFbaInboundApiLog);
                        listShipmentItemsResponse = listShipmentItemsResponse;
                        System.out.println(listShipmentItemsResponse);
                    }
                }
            }

        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }


    /**
     * 测试新的头程流程
     */
    @RequestMapping("/test5")
    @ResponseBody
    public void test5() {
        CreateInboundPlanRequest body = new CreateInboundPlanRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        //添加国家
        List<String> destinationMarketplaces = new ArrayList();
        destinationMarketplaces.add(jsonObject.get("marketplaceId").toString());
        body.setDestinationMarketplaces(destinationMarketplaces);

        //查询头程明细
        List<Map<String, Object>> fbaPlanOrderDetailMap = fbaInboundApiMapper.getTccFbaPlanItemHb("TCJH-241206-1041");
        //计划需要的商品信息
        List<ItemInput> items = new ArrayList();
        for (Map<String, Object> fbaPlanOrderDetail : fbaPlanOrderDetailMap) {
            ItemInput itemInput = new ItemInput();
            //我们自己打包产品（贴标签）
            itemInput.setLabelOwner(LabelOwner.SELLER);
            //特殊产品 的包装 承诺是自己包装)
            //当出现 这个错误 就说明ERROR: White 1 Tier does not require prepOwner but SELLER was assigned. Accepted values: [NONE]" 后台还未预处理
            itemInput.setPrepOwner(PrepOwner.SELLER);
            //发货的sku数量 最小1最大10000
            itemInput.setQuantity(new Integer(fbaPlanOrderDetail.get("BDept").toString()));
            //sku
            itemInput.setMsku(fbaPlanOrderDetail.get("SKU").toString());
            items.add(itemInput);
        }
        body.setItems(items);

        //计划名称，不传默认 最小1最大40
//        body.setName("");

        //发货地址
        AddressInput sourceAddress = new AddressInput();
        //地址1
        sourceAddress.setAddressLine1(jsonObject.get("addressLine1").toString());
        //地址2
        sourceAddress.setAddressLine2(jsonObject.get("addressLine2").toString());
        //城市
        sourceAddress.setCity(jsonObject.get("city").toString());
        //国家 默认是cn
        sourceAddress.setCountryCode("CN");
        //姓名
        sourceAddress.setName(jsonObject.get("name").toString());
        //手机
        sourceAddress.setPhoneNumber(jsonObject.get("phone").toString());
        //邮编
        sourceAddress.setPostalCode(jsonObject.get("postalCode").toString());
        //州
        sourceAddress.setStateOrProvinceCode(jsonObject.get("stateOrProvinceCode").toString());

        body.setSourceAddress(sourceAddress);
        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            //TODO 测试不行 正式可以 可能是数据问题导致 后期在研究
            CreateInboundPlanResponse inboundPlan = api.createInboundPlan(body);
            System.out.println("inboundPlan=" + inboundPlan);

            TsCorresLog tsCorresLog = TsCorresLog.tsCorresLog("createInboundPlan", body.toString(), inboundPlan.toString(), 1);
            tsCorresLogMapper.insert(tsCorresLog);

//            inboundPlan=class CreateInboundPlanResponse {
//                inboundPlanId: wf294daf74-8d88-4bf9-a61f-73cb89da741b
//                operationId: 5599c807-6901-4a9e-8962-6582db23334f
//            }
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }

    /**
     * 第一步 b 通过getInboundOperationStatus获取订单的具体信息,异常状态或者正确 可判断也可以不判断
     */
    @RequestMapping("/test4")
    @ResponseBody
    public void test4() {
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();

        try {
            InboundOperationStatus inboundOperationStatus = api.getInboundOperationStatus("078e82f8-9d03-41e2-83c4-7025182bdcaa");
            inboundOperationStatus = inboundOperationStatus;
            //class InboundOperationStatus {
            //    operation: createInboundPlan
            //    operationId: cc066945-eb79-491b-ae00-4ca80d5ab8cf
            //    operationProblems: []
            //    operationStatus: SUCCESS
            //}
            //TODO operationStatus ：SUCCESS 才成功 当其他状态通过operationProblems 获取到失败状态信息
            System.out.println("inboundOperationStatus=" + inboundOperationStatus);
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }
    }

    /**
     * 第二步。确定哪些可组合在一起
     * 这一步骤对于确定哪些物品可以包装在一起是必要的。由于不同的处理或履行中心的要求,有些物品无法包装在一起。进一步分开的项目可能有折扣。
     */
    @RequestMapping("/test3")
    @ResponseBody
    public void test3() {
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();

        try {
            //TODO 注意事项 在欧盟,SPD的发货只有折扣选择。这些折扣选择可能包括额外要求,包括每个包件重量必须小于15公斤。
            //生成入站计划的可用包装选项。
//            GeneratePackingOptionsResponse generatePackingOptionsResponse = api.generatePackingOptions("wf294daf74-8d88-4bf9-a61f-73cb89da741b");
//            generatePackingOptionsResponse = generatePackingOptionsResponse;
//            class GeneratePackingOptionsResponse {
//                operationId: 6f65fca1-b25f-46a0-957e-52b855822993
//            }
//            System.out.println("generatePackingOptionsResponse="+generatePackingOptionsResponse);


//            TODO 接下来,用 手术。包装选项包含卖方可以选择的包组集,以及有助于卖方选择这些选项的其他信息。其他信息包括与每个选项相关的收费/折扣、每个选项支持的运输方式以及每个选项的到期日
//            ListPackingOptionsResponse listPackingOptionsResponse = api.listPackingOptions("wf294daf74-8d88-4bf9-a61f-73cb89da741b",null,null);
//            listPackingOptionsResponse = listPackingOptionsResponse;

//            class PackingOption {
//                discounts: []
//                expiration: null
//                fees: []
//                packingGroups: [pg5f2abde7-5ea3-4369-bed8-f83c8a1bcda8]
//                packingOptionId: po00000000-0000-0000-0000-000000000000
//                status: ACCEPTED
//                supportedShippingConfigurations: []
//            }
//            System.out.println("listPackingOptionsResponse="+listPackingOptionsResponse);

            //第二步C。每个包装方案中的清单项目
            ListPackingGroupItemsResponse listPackingGroupItemsResponse = api.listPackingGroupItems("wf294daf74-8d88-4bf9-a61f-73cb89da741b","pg5f2abde7-5ea3-4369-bed8-f83c8a1bcda8",null,null);
            System.out.println("listPackingGroupItemsResponse="+listPackingGroupItemsResponse);
//            class ListPackingGroupItemsResponse {
//                items: [class Item {
//                    asin: B0BLZ9MTQF
//                    expiration: null
//                    fnsku: X001O2488B
//                    labelOwner: SELLER
//                    manufacturingLotCode: null
//                    msku: SILU146
//                    prepInstructions: [class PrepInstruction {
//                        fee: class Currency {
//                            currencyCode: null
//                            currencyAmount: null
//                        }
//                        prepOwner: SELLER
//                        prepType: ITEM_LABELING
//                    }]
//                    quantity: 50
//                }, class Item {
//                    asin: B0BD1YMR8H
//                    expiration: null
//                    fnsku: X001MNVH63
//                    labelOwner: SELLER
//                    manufacturingLotCode: null
//                    msku: Y4-6JFR-38OX
//                    prepInstructions: [class PrepInstruction {
//                        fee: class Currency {
//                            currencyCode: null
//                            currencyAmount: null
//                        }
//                        prepOwner: SELLER
//                        prepType: ITEM_LABELING
//                    }]
//                    quantity: 100
//                }]
//                pagination: class Pagination {
//                    nextToken: null
//                }
//            }
            //第二步。选择包装选项
            ConfirmPackingOptionResponse confirmPackingOptionResponse = api.confirmPackingOption("wf294daf74-8d88-4bf9-a61f-73cb89da741b", "po00000000-0000-0000-0000-000000000000");
            System.out.println("confirmPackingOptionResponse=" + confirmPackingOptionResponse);
            //class ConfirmPackingOptionResponse {
            //    operationId: a605bac1-66dd-4957-a586-e04668ed5d96
            //}
//            TsCorresLog tsCorresLog = TsCorresLog.tsCorresLog("listPackingOptions","wf294daf74-8d88-4bf9-a61f-73cb89da741b",listPackingOptionsResponse.toString(),1);
//            tsCorresLogMapper.insert(tsCorresLog);
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }
    }

    /**
     * 第三步。提供方框内容信息(如有) 装箱信息
     */
    @RequestMapping("/test11")
    @ResponseBody
    public void test11() {
        SetPackingInformationRequest body = new SetPackingInformationRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        //添加国家
        List<PackageGroupingInput> packageGroupings = new ArrayList();
        PackageGroupingInput packageGroupingInput = new PackageGroupingInput();
        //shipmentId packingGroupId只能选择一个
        packageGroupingInput.setPackingGroupId("pg5f2abde7-5ea3-4369-bed8-f83c8a1bcda8");
        List<BoxInput> boxInputs = new ArrayList<>();
        //查询装箱数据
        List<Map<String, Object>> fbaFbaBoxDetailMapList = fbaInboundApiMapper.getFbaFbaBoxDetail();
        for (Map<String, Object> fbaFbaBoxDetail : fbaFbaBoxDetailMapList) {
            BoxInput boxInput = new BoxInput();
            //箱子信息有卖家提供的二维码提供
            boxInput.setContentInformationSource(BoxContentInformationSource.BOX_CONTENT_PROVIDED);
            //包装尺寸
            Dimensions dimensions = new Dimensions();
            dimensions.setHeight(new BigDecimal(fbaFbaBoxDetail.get("Height").toString()));
            dimensions.setLength(new BigDecimal(fbaFbaBoxDetail.get("Length").toString()));
            dimensions.setWidth(new BigDecimal(fbaFbaBoxDetail.get("Width").toString()));
            //厘米
            dimensions.setUnitOfMeasurement(UnitOfMeasurement.CM);
            boxInput.setDimensions(dimensions);

            //重量
            Weight weight = new Weight();
            weight.setUnit(UnitOfWeight.KG);
            weight.setValue(new BigDecimal(fbaFbaBoxDetail.get("Weight").toString()));
            boxInput.setWeight(weight);
            JSONArray jsonArray1 = JSONArray.parseArray(fbaFbaBoxDetail.get("ProductInfo").toString());
            boxInput.setQuantity(1);
            List<ItemInput> items = new ArrayList();
            for (int i = 0; i < jsonArray1.size(); i++) {
                JSONObject jsonObject1 = JSONObject.parseObject(String.valueOf(jsonArray1.get(i)));
                //TODO  items 商品信息 不传后续generatePlacementOptions 会基于createInboundPlan传递 传值就会基于此箱级信息的
                //计划需要的商品信息
                ItemInput itemInput = new ItemInput();
                //我们自己打包产品
                itemInput.setLabelOwner(LabelOwner.SELLER);
                //特殊产品 的包装 承诺是自己包装
                itemInput.setPrepOwner(PrepOwner.SELLER);
                //发货的sku数量 最小1最大10000
                itemInput.setQuantity(Integer.valueOf(jsonObject1.get("numRealityDeliver").toString()));
                //sku
                itemInput.setMsku(jsonObject1.get("sku").toString());
                items.add(itemInput);

            }
            boxInput.setItems(items);
            boxInputs.add(boxInput);
        }




        packageGroupingInput.setBoxes(boxInputs);
        packageGroupings.add(packageGroupingInput);
        body.setPackageGroupings(packageGroupings);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            //不允许抛弃该数据  只能重新创建入站plan
            SetPackingInformationResponse setPackingInformationResponse = api.setPackingInformation("wf294daf74-8d88-4bf9-a61f-73cb89da741b", body);
            setPackingInformationResponse = setPackingInformationResponse;
            System.out.println("setPackingInformationResponse=" + setPackingInformationResponse);
//            setPackingInformationResponse=class SetPackingInformationResponse {
//                operationId: 395fa3f9-a5d9-45a6-9eb0-47e3a1799575
//            }
            TsCorresLog tsCorresLog = TsCorresLog.tsCorresLog("setPackingInformation", "pg9a1dc829-42cf-4352-95a3-27c1cebdd772", setPackingInformationResponse.toString(), 1);
            tsCorresLogMapper.insert(tsCorresLog);
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }


    /**
     * 第四步。为目的地履行中心生成和查看选项
     */
    @RequestMapping("/test12")
    @ResponseBody
    public void test12() {
        GeneratePlacementOptionsRequest body = new GeneratePlacementOptionsRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        //添加国家
//        List<CustomPlacementInput> customPlacementList = new ArrayList<>();
//        CustomPlacementInput customPlacementInput = new CustomPlacementInput();
//        customPlacementInput.setWarehouseId("LBE1");
////        计划需要的商品信息
//        List<ItemInput> items = new ArrayList();
//        ItemInput itemInput = new ItemInput();
//        //我们自己打包产品
//        itemInput.setLabelOwner(LabelOwner.SELLER);
//        //特殊产品 的包装 承诺是自己包装
//        itemInput.setPrepOwner(PrepOwner.SELLER);
//        //发货的sku数量 最小1最大10000
//        itemInput.setQuantity(100);
//        //sku
//        itemInput.setMsku("Y4-6JFR-38OX");
//        items.add(itemInput);
//
//        ItemInput itemInput11 = new ItemInput();
//        //我们自己打包产品
//        itemInput11.setLabelOwner(LabelOwner.SELLER);
//        //特殊产品 的包装 承诺是自己包装
//        itemInput11.setPrepOwner(PrepOwner.SELLER);
//        //发货的sku数量 最小1最大10000
//        itemInput11.setQuantity(50);
//        //sku
//        itemInput11.setMsku("SILU146");
//        items.add(itemInput11);
//        customPlacementInput.setItems(items);
//
//        customPlacementList.add(customPlacementInput);
//        body.setCustomPlacement(customPlacementList);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
//            CustomPlacement要添加到计划中的自定义放置选项。这里提供的细节仅用于印度(IN - A21TJRUUN4KGV)市场。
//            GeneratePlacementOptionsResponse generatePlacementOptionsResponse = api.generatePlacementOptions("wf294daf74-8d88-4bf9-a61f-73cb89da741b",body);
//            generatePlacementOptionsResponse = generatePlacementOptionsResponse;
//            System.out.println("generatePlacementOptionsResponse="+generatePlacementOptionsResponse);
//            generatePlacementOptionsResponse=class GeneratePlacementOptionsResponse {
//                operationId: 85698a18-bc97-4822-994b-930001f78aa2
//            }

//            //TODO 这里看是否能获取到配置费 需要去核实 （获得分箱的fbaid 可以通过getShipment获取到亚马逊仓库信息，但是货件还是未经证实的）
            ListPlacementOptionsResponse listPlacementOptionsResponse = api.listPlacementOptions("wf294daf74-8d88-4bf9-a61f-73cb89da741b", null, null);
            listPlacementOptionsResponse = listPlacementOptionsResponse;
            System.out.println("listPlacementOptionsResponse=" + listPlacementOptionsResponse);
//            listPlacementOptionsResponse=class ListPlacementOptionsResponse {
//                pagination: class Pagination {
//                    nextToken: null
//                }
//                placementOptions: [class PlacementOption {
//                    discounts: []
//                    expiration: 2024-09-14T01:34:44.960Z
//                    fees: [class Incentive {
//                        description: Placement service fee represents service to inbound with minimal shipment splits and destinations of skus
//                        target: Placement Services
//                        type: FEE
//                        value: class Currency {
//                            currencyCode: null
//                            currencyAmount: null
//                        }
//                    }]
//                    placementOptionId: pl54b41359-b57f-4866-80f7-44884c4285c3
//                    shipmentIds: [shff1dcd94-106f-452b-b38b-6e889029236d]
//                    status: OFFERED
//                }, class PlacementOption {
//                    discounts: []
//                    expiration: 2024-09-14T01:34:44.960Z
//                    fees: [class Incentive {
//                        description: Placement service fee represents service to inbound with minimal shipment splits and destinations of skus
//                        target: Placement Services
//                        type: FEE
//                        value: class Currency {
//                            currencyCode: null
//                            currencyAmount: null
//                        }
//                    }]
//                    placementOptionId: pl59547cd8-eeb8-477f-843a-9e6d97271871
//                    shipmentIds: [sh2b625266-89d6-4c30-9ba0-673120ad5685]
//                    status: OFFERED
//                }, class PlacementOption {
//                    discounts: []
//                    expiration: 2024-09-14T01:34:44.960Z
//                    fees: [class Incentive {
//                        description: Placement service fee represents service to inbound with minimal shipment splits and destinations of skus
//                        target: Placement Services
//                        type: FEE
//                        value: class Currency {
//                            currencyCode: null
//                            currencyAmount: null
//                        }
//                    }]
//                    placementOptionId: pl5a0617ae-3b0c-48f9-bbf1-269290e10bdd
//                    shipmentIds: [sh5e69387f-44d2-45c3-b4e6-1a76f4c2cc53]
//                    status: OFFERED
//                }]
//            }

            // 通过listShipmentBoxes 可以获取到每个fba对应箱子的重量和对应箱子被分在哪个fba里面
            TsCorresLog tsCorresLog = TsCorresLog.tsCorresLog("listPlacementOptions", "wf294daf74-8d88-4bf9-a61f-73cb89da741b", listPlacementOptionsResponse.toString(), 1);
            tsCorresLogMapper.insert(tsCorresLog);
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }


    /**
     * 第五步。输入运输数据并生成运输选项
     */
    @RequestMapping("/test16")
    @ResponseBody
    public void test16() {
        GenerateTransportationOptionsRequest body = new GenerateTransportationOptionsRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        List<ShipmentTransportationConfiguration> shipmentTransportationConfigurationList = new ArrayList<>();
        ShipmentTransportationConfiguration shipmentTransportationConfiguration = new ShipmentTransportationConfiguration();
        //货件id
        shipmentTransportationConfiguration.setShipmentId("sh244670a6-dc09-498d-a907-260eb0c0a381");
        //发货日期
        WindowInput windowInput = new WindowInput();
        windowInput.setStart(OffsetDateTime.parse(DateUtils.convertDateToTDate(new Date())));
        shipmentTransportationConfiguration.setReadyToShipWindow(windowInput);

        shipmentTransportationConfigurationList.add(shipmentTransportationConfiguration);

        shipmentTransportationConfiguration = new ShipmentTransportationConfiguration();
        shipmentTransportationConfiguration.setShipmentId("sh5bf6acc3-96b0-4a94-a72f-7a4e1c948139");
        shipmentTransportationConfiguration.setReadyToShipWindow(windowInput);
        shipmentTransportationConfigurationList.add(shipmentTransportationConfiguration);

        shipmentTransportationConfiguration = new ShipmentTransportationConfiguration();
        shipmentTransportationConfiguration.setShipmentId("shb8820358-57bd-4c49-ab64-b0ac3c0cc424");
        shipmentTransportationConfiguration.setReadyToShipWindow(windowInput);
        shipmentTransportationConfigurationList.add(shipmentTransportationConfiguration);

        body.setPlacementOptionId("pl3106775c-74de-43d8-a6ea-34bde3d0a61c");
        body.setShipmentTransportationConfigurations(shipmentTransportationConfigurationList);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            GenerateTransportationOptionsResponse generateTransportationOptionsResponse = api.generateTransportationOptions("wf294daf74-8d88-4bf9-a61f-73cb89da741b", body);
            generateTransportationOptionsResponse = generateTransportationOptionsResponse;
            System.out.println("generateTransportationOptionsResponse=" + generateTransportationOptionsResponse);
//            class GenerateTransportationOptionsResponse {
//                operationId: 87be8746-f5c0-44f4-ace9-8e935de33a28
//            }
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }

    /**
     * 交货窗口为七天期,卖方可在此期间将货物交付到目的地履行中心。该窗口用于提供在亚马逊履行中心的货物预期到达日期和时间。对于所有没有与履行中心预约时间的货物,都需要一个可用的交付窗口选项。例如,通过非伙伴承运人的所有货运都需要一个经确认的交货窗口。
     */
    @RequestMapping("/test17")
    @ResponseBody
    public void test17() {
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            GenerateDeliveryWindowOptionsResponse generateTransportationOptionsResponse = api.generateDeliveryWindowOptions(
                    "wf294daf74-8d88-4bf9-a61f-73cb89da741b",
                    "shb8820358-57bd-4c49-ab64-b0ac3c0cc424");
            generateTransportationOptionsResponse = generateTransportationOptionsResponse;
            System.out.println("generateTransportationOptionsResponse=" + generateTransportationOptionsResponse);
            //class GenerateDeliveryWindowOptionsResponse {
            //    operationId: b7d0f29a-966e-4c35-a5eb-546140512971
            //    operationId: 27a8cdeb-bab4-4a53-99d6-067c513e6afb
            //    operationId: 598ed144-f93c-47dd-9bd9-b86c9f8a9dfb
            //}
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }

    /**
     * 检索货物的所有运输选项
     */
    @RequestMapping("/test18")
    @ResponseBody
    public void test18() {
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            Boolean sd = true;
            ListTransportationOptionsResponse listTransportationOptionsResponse = null;
            String paginationToken = null;
            while (sd) {
                //TODO 我们使用其他的承运人 （注意 这里是获取可以选择的承运人数据 我们选择其他承运人）  根据分组来获取对应的承运人
                listTransportationOptionsResponse = api.listTransportationOptions(
                        "wf294daf74-8d88-4bf9-a61f-73cb89da741b",
                        20,paginationToken , "pl3106775c-74de-43d8-a6ea-34bde3d0a61c",
                        null);
                listTransportationOptionsResponse = listTransportationOptionsResponse;
                for (TransportationOption transportationOption : listTransportationOptionsResponse.getTransportationOptions()){
                    if (transportationOption.getCarrier() != null){
                        if(transportationOption.getCarrier().getName().equals("Other")){
                            transportationOption = transportationOption;
                        }
                    }
                }
                if (listTransportationOptionsResponse.getPagination().getNextToken() == null) {
                    sd = false;
                }else {
                    paginationToken = listTransportationOptionsResponse.getPagination().getNextToken();
                }
            }

            System.out.println("listTransportationOptionsResponse=" + listTransportationOptionsResponse);
            //shippingMode: GROUND_SMALL_PARCEL 地面小包裹  shippingSolution: USE_YOUR_OWN_CARRIER 其他承运人
//            shipmentId: shff1dcd94-106f-452b-b38b-6e889029236d
//            shippingMode: GROUND_SMALL_PARCEL
//            shippingSolution: USE_YOUR_OWN_CARRIER
//            transportationOptionId: tof4e22d54-cb5e-430d-b4e5-a0b8faedfaf6 sh244670a6-dc09-498d-a907-260eb0c0a381
//            transportationOptionId: tob1391732-cd56-429e-8540-3ef27564b77d sh5bf6acc3-96b0-4a94-a72f-7a4e1c948139
//            transportationOptionId: tof6e80e47-9234-4318-bad8-8fb662f95b35 shb8820358-57bd-4c49-ab64-b0ac3c0cc424

            TsCorresLog tsCorresLog = TsCorresLog.tsCorresLog("listTransportationOptions", "shc04e5883-599d-4bf6-a7c7-138c0af00a53", listTransportationOptionsResponse.toString(), 1);
            tsCorresLogMapper.insert(tsCorresLog);
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }

    /**
     * 检索货物的所有送货窗口选项
     */
    @RequestMapping("/test19")
    @ResponseBody
    public void test19() {
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            ListDeliveryWindowOptionsResponse listDeliveryWindowOptionsResponse = api.listDeliveryWindowOptions(
                    "wf294daf74-8d88-4bf9-a61f-73cb89da741b", "shb8820358-57bd-4c49-ab64-b0ac3c0cc424", null, null);
            listDeliveryWindowOptionsResponse = listDeliveryWindowOptionsResponse;
            System.out.println("listDeliveryWindowOptionsResponse=" + listDeliveryWindowOptionsResponse);
            //        deliveryWindowOptionId: sh244670a6-dc09-498d-a907-260eb0c0a381 dw5d080e87-7ad5-4f2e-b3cf-559aa08d6380
            //        deliveryWindowOptionId: sh5bf6acc3-96b0-4a94-a72f-7a4e1c948139 dwdef1bd1d-7cc1-4b00-9783-2ed6aa09741f
            //        deliveryWindowOptionId: shb8820358-57bd-4c49-ab64-b0ac3c0cc424 dw52b8660e-c262-431d-949e-fa6c907d192f

            TsCorresLog tsCorresLog = TsCorresLog.tsCorresLog("listDeliveryWindowOptions", "sh5e69387f-44d2-45c3-b4e6-1a76f4c2cc53", listDeliveryWindowOptionsResponse.toString(), 1);
            tsCorresLogMapper.insert(tsCorresLog);
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }

    /**
     * 获取货件的信息 随时都可以查询
     */
    @RequestMapping("/test15")
    @ResponseBody
    public void test15() {
        GeneratePlacementOptionsRequest body = new GeneratePlacementOptionsRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {

            //TODO 可以获取到货件编码 和fba号  解决以前1.0上需要导入的操作
            Shipment shipment = api.getShipment("wf294daf74-8d88-4bf9-a61f-73cb89da741b", "sh5bf6acc3-96b0-4a94-a72f-7a4e1c948139");
            InboundPlan inboundPlan = api.getInboundPlan("wf294daf74-8d88-4bf9-a61f-73cb89da741b");
            inboundPlan = inboundPlan;
//            shipment = shipment;
//            ListShipmentItemsResponse listShipmentItemsResponse = api.listShipmentItems("wf294daf74-8d88-4bf9-a61f-73cb89da741b","sh2b625266-89d6-4c30-9ba0-673120ad5685",null,null);
//            System.out.println("shipment="+shipment);
//            System.out.println("listShipmentItemsResponse="+listShipmentItemsResponse);
            //class Shipment {
            //    amazonReferenceId: null
            //    contactInformation: null
            //    dates: null
            //    destination: class ShipmentDestination {
            //        address: class Address {
            //            addressLine1: Plot 1, Lyons Park,
            //            addressLine2: Sayer Dr
            //            city: Coventry
            //            companyName: null
            //            countryCode: GB
            //            email: null
            //            name: Amazon EU SARL (UK)
            //            phoneNumber: null
            //            postalCode: CV5 9PF
            //            stateOrProvinceCode: West Midlands
            //        }
            //        destinationType: AMAZON_WAREHOUSE
            //        warehouseId: BHX4
            //    }
            //    freightInformation: null
            //    name: null
            //    placementOptionId: pl5c5b8a95-de27-43d4-9a51-38c1407600be
            //    selectedDeliveryWindow: null
            //    selectedTransportationOptionId: null
            //    selfShipAppointmentDetails: null
            //    shipmentConfirmationId: null
            //    shipmentId: shd3b4d3f0-c8e5-4ba7-9563-d1c3a0f06651
            //    source: class ShipmentSource {
            //        address: class Address {
            //            addressLine1: WAN AN JIE DAO QUAN ZHOU SILU DIAN ZI SHANGWU YOUXIAN GONGSI
            //            addressLine2: YANG GUANG GUO JI GUANG CHANG 2HAO LOU 2106
            //            city: QUAN ZHOU SHI
            //            companyName: null
            //            countryCode: CN
            //            email: null
            //            name: SILULCM
            //            phoneNumber: 15280576826
            //            postalCode: 362010
            //            stateOrProvinceCode: FU JIAN SHENG
            //        }
            //        sourceType: SELLER_FACILITY
            //    }
            //    status: UNCONFIRMED
            //    trackingDetails: null
            //}
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }


    /**
     * 确认入站计划的放置选项。一旦确认,就不能为入站计划更改。 这一步还是下一步就会后台产生fba货件
     */
    @RequestMapping("/test206")
    @ResponseBody
    public void test206() {
        GeneratePlacementOptionsRequest body = new GeneratePlacementOptionsRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            //只能使用一个配置placementOptionId
            ConfirmPlacementOptionResponse confirmPlacementOptionResponse = api.confirmPlacementOption("wf294daf74-8d88-4bf9-a61f-73cb89da741b",
                    "pl3106775c-74de-43d8-a6ea-34bde3d0a61c");
            confirmPlacementOptionResponse = confirmPlacementOptionResponse;
            System.out.println("confirmPlacementOptionResponse=" + confirmPlacementOptionResponse);
            //class ConfirmPlacementOptionResponse {
            //    operationId: ab6f0e40-5f2c-430f-84e0-31add9ea6037
            //}
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }


    /**
     * 在入站计划中,为所选的发货确认交货窗口选项。在使用此API之前,必须确认放置选项。一旦确认,就无法生成新的交付窗口选项,但可在货物运输结束前更新选定的交付窗口选项。该窗口用于提供货物到达仓库的预期时间。所有有计划的交通工具 要求在运输选项确认之前确认一个送货窗口
     */
    @RequestMapping("/test170")
    @ResponseBody
    public void test170() {
        GeneratePlacementOptionsRequest body = new GeneratePlacementOptionsRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();


        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            ConfirmDeliveryWindowOptionsResponse confirmDeliveryWindowOptionsResponse = api.confirmDeliveryWindowOptions(
                    "wf294daf74-8d88-4bf9-a61f-73cb89da741b",
                    "shb8820358-57bd-4c49-ab64-b0ac3c0cc424",
                    "dw52b8660e-c262-431d-949e-fa6c907d192f");
            //        deliveryWindowOptionId: sh244670a6-dc09-498d-a907-260eb0c0a381 dw5d080e87-7ad5-4f2e-b3cf-559aa08d6380
            //        deliveryWindowOptionId: sh5bf6acc3-96b0-4a94-a72f-7a4e1c948139 dwdef1bd1d-7cc1-4b00-9783-2ed6aa09741f
            //        deliveryWindowOptionId: shb8820358-57bd-4c49-ab64-b0ac3c0cc424 dw52b8660e-c262-431d-949e-fa6c907d192f
            confirmDeliveryWindowOptionsResponse = confirmDeliveryWindowOptionsResponse;
            System.out.println("confirmDeliveryWindowOptionsResponse=" + confirmDeliveryWindowOptionsResponse);
            //class ConfirmDeliveryWindowOptionsResponse {
            //    operationId: 2cf087f7-5309-4b21-8a7a-2a2db331eae8
            //    operationId: 0c9b175b-11a6-4511-88c3-047580ffb6aa
            //    operationId: 078e82f8-9d03-41e2-83c4-7025182bdcaa
            //}
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }


    /**
     * 重要的
     *
     * 在确认运输请求后,如果卖方决定不希望亚马逊伙伴的承运人装运进港货物,则 操作可以取消运输请求.请注意,对于小包裹装运,卖方在确认运输请求无效后有24小时时间。对于少于卡车装载量/全部卡车装载量(立特/超光速)的货物,卖方在确认运输请求无效后有一个小时的时间。在宽限期到期后,卖方的帐户支付运费。cancelInboundPlan
     */

    /**
     * 确认入境计划的所有交通选择。在使用此API之前,必须确认放置选项。一旦确认,就无法生成新的运输选项或确认入站计划。
     */
    @RequestMapping("/test180")
    @ResponseBody
    public void test180() {
        ConfirmTransportationOptionsRequest body = new ConfirmTransportationOptionsRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();

//            transportationOptionId: tof4e22d54-cb5e-430d-b4e5-a0b8faedfaf6 sh244670a6-dc09-498d-a907-260eb0c0a381
//            transportationOptionId: tob1391732-cd56-429e-8540-3ef27564b77d sh5bf6acc3-96b0-4a94-a72f-7a4e1c948139
//            transportationOptionId: tof6e80e47-9234-4318-bad8-8fb662f95b35 shb8820358-57bd-4c49-ab64-b0ac3c0cc424
        List<TransportationSelection> transportationSelections = new ArrayList();
        TransportationSelection transportationSelection = new TransportationSelection();
        transportationSelection.setShipmentId("sh244670a6-dc09-498d-a907-260eb0c0a381");
        transportationSelection.setTransportationOptionId("tof4e22d54-cb5e-430d-b4e5-a0b8faedfaf6");
        transportationSelections.add(transportationSelection);

        transportationSelection = new TransportationSelection();
        transportationSelection.setShipmentId("sh5bf6acc3-96b0-4a94-a72f-7a4e1c948139");
        transportationSelection.setTransportationOptionId("tob1391732-cd56-429e-8540-3ef27564b77d");
        transportationSelections.add(transportationSelection);

        transportationSelection = new TransportationSelection();
        transportationSelection.setShipmentId("shb8820358-57bd-4c49-ab64-b0ac3c0cc424");
        transportationSelection.setTransportationOptionId("tof6e80e47-9234-4318-bad8-8fb662f95b35");
        transportationSelections.add(transportationSelection);
        body.setTransportationSelections(transportationSelections);

        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            ConfirmTransportationOptionsResponse confirmTransportationOptionsResponse = api.confirmTransportationOptions(
                    "wf294daf74-8d88-4bf9-a61f-73cb89da741b",
                    body);
            confirmTransportationOptionsResponse = confirmTransportationOptionsResponse;
            System.out.println("confirmTransportationOptionsResponse=" + confirmTransportationOptionsResponse);
//            50389dad-97df-4ffa-939c-5f3fb42e3458
//            "message": "ERROR: No placement option is confirmed for inboundPlan wf294daf74-8d88-4bf9-a61f-73cb89da741b.",

        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }

    /**
     * 印刷标签
     */
    @RequestMapping("/test190")
    @ResponseBody
    public void test190() {
        ConfirmTransportationOptionsRequest body = new ConfirmTransportationOptionsRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        SellerSecretsVO secretsVO;
        secretsVO = new SellerSecretsVO();
        FbaInboundApiV0 api;
        secretsVO.setAWSAuthenticationCredentials_AK(MyConfig.getAmazonAwsAccessKey());
        secretsVO.setAWSAuthenticationCredentials_SK(MyConfig.getAmazonAwsAccessSecret());
        secretsVO.setAWSAuthenticationCredentialsProvider_roleArn(MyConfig.getAmazonRoleArn());
        secretsVO.setlWAAuthorizationCredentials_clientid(MyConfig.getAmazonLwaClientKey());
        secretsVO.setLWAAuthorizationCredentials_clientSecret(encryptSecret);
        secretsVO.setSeller_id(jsonObject.get("sellerId").toString());
        secretsVO.setLWAAuthorizationCredentials_refreshToken(jsonObject.get("refreshToken").toString());
        secretsVO.setMarketPlace(MarketplaceEnum.NORTH.getCode());
        api = Helper.buildApi(secretsVO, FbaInboundApiV0.class);

        List<String> packageLabelsToPrint = Arrays.asList("1");
        GetLabelsResponse getLabelsResponse =
                null;
        try {
            getLabelsResponse = api.getLabels("FBA18DT058DZ",
                    "PackageLabel_Plain_Paper",
                    "BARCODE_2D",
                    null,
                    packageLabelsToPrint,
                    null,
                    1, 0);
            getLabelsResponse = getLabelsResponse;
            System.out.println("getLabelsResponse="+getLabelsResponse);

//            List<String> shipmentIdList = new ArrayList<>();
//            shipmentIdList.add("FBA15GV5KVMM");
//            GetShipmentsResponse getShipmentsResponse = api.getShipments("SHIPMENT", jsonObject.get("sellerId").toString(), null, shipmentIdList, null, null, null);
//            getShipmentsResponse = getShipmentsResponse;
        } catch (com.bo.sellingpartnerapi.Authorization.invoker.ApiException e) {
            e.printStackTrace();
        }
    }

    /**
     * 提供入站计划中框包的分页列表。
     */
    @RequestMapping("/test20")
    @ResponseBody
    public void test20() {
        ConfirmTransportationOptionsRequest body = new ConfirmTransportationOptionsRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();

        List<TransportationSelection> transportationSelections = new ArrayList();
        TransportationSelection transportationSelection = new TransportationSelection();
        transportationSelection.setShipmentId("sh244670a6-dc09-498d-a907-260eb0c0a381");
        transportationSelection.setTransportationOptionId("pl3106775c-74de-43d8-a6ea-34bde3d0a61c");
        transportationSelections.add(transportationSelection);
        body.setTransportationSelections(transportationSelections);

        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
            ListInboundPlanBoxesResponse listInboundPlanBoxesResponse = api.listInboundPlanBoxes(
                    "wf294daf74-8d88-4bf9-a61f-73cb89da741b", null, null);
            listInboundPlanBoxesResponse = listInboundPlanBoxesResponse;
            System.out.println("listInboundPlanBoxesResponse=" + listInboundPlanBoxesResponse);
            //class ListInboundPlanBoxesResponse {
            //    boxes: [class Box {
            //        boxId: FBA15J84L7ZRU000001
            //        contentInformationSource: BARCODE_2D
            //        destinationRegion: null
            //        dimensions: class Dimensions {
            //            height: 37.9
            //            length: 49.9
            //            unitOfMeasurement: IN
            //            width: 41
            //        }
            //        items: []
            //        packageId: pk004d8ddb-2ca4-4278-8548-8297cd01be4c
            //        quantity: 1
            //        templateName: null
            //        weight: class Weight {
            //            unit: KG
            //            value: 12
            //        }
            //    }, class Box {
            //        boxId: FBA15J84L7ZRU000002
            //        contentInformationSource: BARCODE_2D
            //        destinationRegion: null
            //        dimensions: class Dimensions {
            //            height: 37.9
            //            length: 49.9
            //            unitOfMeasurement: IN
            //            width: 41
            //        }
            //        items: []
            //        packageId: pk0070a8f3-1bb4-4bff-9cd6-465275ba2bd0
            //        quantity: 1
            //        templateName: null
            //        weight: class Weight {
            //            unit: KG
            //            value: 12
            //        }
            //    }, class Box {
            //        boxId: FBA15J84L7ZRU000003
            //        contentInformationSource: BARCODE_2D
            //        destinationRegion: null
            //        dimensions: class Dimensions {
            //            height: 37.9
            //            length: 49.9
            //            unitOfMeasurement: IN
            //            width: 41
            //        }
            //        items: []
            //        packageId: pk030e9177-22cb-4a7f-990b-ee87c5b55722
            //        quantity: 1
            //        templateName: null
            //        weight: class Weight {
            //            unit: KG
            //            value: 12
            //        }
            //    }, class Box {
            //        boxId: FBA15J84L7ZRU000004
            //        contentInformationSource: BARCODE_2D
            //        destinationRegion: null
            //        dimensions: class Dimensions {
            //            height: 37.9
            //            length: 49.9
            //            unitOfMeasurement: IN
            //            width: 41
            //        }
            //        items: []
            //        packageId: pk04bdb354-d03d-471b-ab64-78f104a87d1b
            //        quantity: 1
            //        templateName: null
            //        weight: class Weight {
            //            unit: KG
            //            value: 12
            //        }
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }
////
////    /**
////     * 更新货物的追踪细节。 TODO 未测试通过 提示说不允许 操作UpdateShipmentTrackingDetails只能处理已确认非pcp运输选项的货物
////     */
////    @RequestMapping("/test22")
////    @ResponseBody
////    public void test22() {
////        UpdateShipmentTrackingDetailsRequest body = new UpdateShipmentTrackingDetailsRequest();
////        //平台
////        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
////        if (tbPlatform == null){
////            return;
////        }
////        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());
////
////        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
////                .addLeftJoin("TP_AmazonSeller tsell on tsell.SellerId = A.SellerId")//卖家管理
////                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
////                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
////                .addField("ts.AmazonMarketplaceId AS marketplaceId")
////                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
////                .addField("tc.name AS countryName,tc.code AS countryCode")
////                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
////                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
////                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
////                .queryMap();
////        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
////        JSONObject jsonObject = jsonArray.getJSONObject(0);
////
////        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
////                .clientId(MyConfig.getAmazonLwaClientKey())
////                .clientSecret(encryptSecret)
////                .refreshToken(jsonObject.get("refreshToken").toString())
////                .endpoint(MyConfig.getAmazonLwaEndpoint())
////                .build();
////
////        //TODO 跟踪信息输入,用于低卡车(LTL)和小包裹发货(SPD)。
////        TrackingDetailsInput trackingDetailsInput = new TrackingDetailsInput();
////        //包含输入信息更新小包裹递送(SPD)跟踪信息。
////        SpdTrackingDetailInput spdTrackingDetail = new SpdTrackingDetailInput();
////        //小包裹派递(SPD)追踪物品输入清单。
////        List<SpdTrackingItemInput> spdTrackingItems = new ArrayList();
////        SpdTrackingItemInput spdTrackingItemInput = new SpdTrackingItemInput();
////        spdTrackingItemInput.setBoxId("pk0070a8f3-1bb4-4bff-9cd6-465275ba2bd0");
////        spdTrackingItemInput.setTrackingId("SFHJ12312323");
////        spdTrackingItems.add(spdTrackingItemInput);
////        spdTrackingDetail.setSpdTrackingItems(spdTrackingItems);
////        trackingDetailsInput.setSpdTrackingDetail(spdTrackingDetail);
////        body.setTrackingDetails(trackingDetailsInput);
////
////        FbaInboundApi api = new FbaInboundApi.Builder()
////                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
////                .endpoint(jsonObject.get("amazonServiceUrl").toString())
////                .build();
////        try {
////
////            UpdateShipmentTrackingDetailsResponse updateShipmentTrackingDetailsResponse = api.updateShipmentTrackingDetails(
////                    "wf294daf74-8d88-4bf9-a61f-73cb89da741b",
////                    "shd3b4d3f0-c8e5-4ba7-9563-d1c3a0f06651",
////                    body);
////            updateShipmentTrackingDetailsResponse = updateShipmentTrackingDetailsResponse;
////            System.out.println("updateShipmentTrackingDetailsResponse="+updateShipmentTrackingDetailsResponse);
////
////        } catch (ApiException e) {
////            System.out.println("ApiException = " + e.getResponseBody());
////            e.printStackTrace();
////        } catch (LWAException e) {
////            e.printStackTrace();
////        }
////
////    }
////
////
////    /**
////     * 更新现有货件的名称。
////     */
////    @RequestMapping("/test23")
////    @ResponseBody
////    public void test23() {
////        UpdateShipmentNameRequest body = new UpdateShipmentNameRequest();
////        body.setName("FBA15J84L7ZR-BHX4-1");
////        //平台
////        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
////        if (tbPlatform == null){
////            return;
////        }
////        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());
////
////        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
////                .addLeftJoin("TP_AmazonSeller tsell on tsell.SellerId = A.SellerId")//卖家管理
////                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
////                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
////                .addField("ts.AmazonMarketplaceId AS marketplaceId")
////                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
////                .addField("tc.name AS countryName,tc.code AS countryCode")
////                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
////                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
////                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
////                .queryMap();
////        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
////        JSONObject jsonObject = jsonArray.getJSONObject(0);
////
////        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
////                .clientId(MyConfig.getAmazonLwaClientKey())
////                .clientSecret(encryptSecret)
////                .refreshToken(jsonObject.get("refreshToken").toString())
////                .endpoint(MyConfig.getAmazonLwaEndpoint())
////                .build();
////
////        FbaInboundApi api = new FbaInboundApi.Builder()
////                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
////                .endpoint(jsonObject.get("amazonServiceUrl").toString())
////                .build();
////        try {
////
////              api.updateShipmentName(
////                    "wf294daf74-8d88-4bf9-a61f-73cb89da741b",
////                    "shd3b4d3f0-c8e5-4ba7-9563-d1c3a0f06651",
////                    body);
////            System.out.println("成功!");
////        } catch (ApiException e) {
////            System.out.println("ApiException = " + e.getResponseBody());
////            e.printStackTrace();
////        } catch (LWAException e) {
////            e.printStackTrace();
////        }
////
////    }
////

    /**
     * 取消入站计划。如果取消是在无效窗口之外进行的，可能会收取费用。亚马逊合作承运人的窗口是小包裹递送(SPD) 24小时，小卡车运输(LTL) 1小时
     */
    @RequestMapping("/test24")
    @ResponseBody
    public void test24() {
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null){
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();

        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {

            CancelInboundPlanResponse cancelInboundPlanResponse = api.cancelInboundPlan(
                    "wf294daf74-8d88-4bf9-a61f-73cb89da741b"
                   );
            cancelInboundPlanResponse = cancelInboundPlanResponse;
            System.out.println("cancelInboundPlanResponse = " + cancelInboundPlanResponse);
            //cancelInboundPlanResponse = class CancelInboundPlanResponse {
            //    operationId: 3f72913f-175b-4e4b-9d78-c7212363605a
            //}
        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }
//
//    @RequestMapping("/test24")
//    @ResponseBody
//    public void test25() {
//        try {
//            timerTcwProformaInvoiceDaily.getProformaInvoiceDaily();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }

    /**
     * 提供入站计划中项目包的分页列表。。
     */
    @RequestMapping("/test200")
    @ResponseBody
    public void test200() {
        ConfirmTransportationOptionsRequest body = new ConfirmTransportationOptionsRequest();
        //平台
        TbPlatform tbPlatform = new TbPlatform().setCode("PTBM001").queryFirst();
        if (tbPlatform == null) {
            return;
        }
        String encryptSecret = AESUtil.aesDecrypt(tbPlatform.getEncryptSecret());

        List<Map<String, Object>> tpAmazonShopList = new TpAmazonShop()
                .addLeftJoin("TP_AmazonSeller tsell on tsell.id = A.amazonSellerId")//卖家管理
                .addField("tsell.refreshToken as refreshToken,tsell.regionCode as regionCode,tsell.regionName")
                .addLeftJoin("TB_Site ts on ts.id = A.SiteId")//站点
                .addField("ts.AmazonMarketplaceId AS marketplaceId")
                .addLeftJoin("TB_Country tc on tc.id = ts.CountryId")//国家
                .addField("tc.name AS countryName,tc.code AS countryCode")
                .addLeftJoin("TP_AmazonRegion tar on tar.Code = ts.regionCode")//平台地区
                .addField("tar.AwsRegion awsRegion,tar.AmazonServiceUrl amazonServiceUrl,tar.code amazonRegionCode")
                .where(" A.Guid = 'ae1ad28c-501f-472f-b854-2371b95de2b4'")
                .queryMap();
        JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(tpAmazonShopList));
        JSONObject jsonObject = jsonArray.getJSONObject(0);

        LWAAuthorizationCredentials lwaAuthorizationCredentials = LWAAuthorizationCredentials.builder()
                .clientId(MyConfig.getAmazonLwaClientKey())
                .clientSecret(encryptSecret)
                .refreshToken(jsonObject.get("refreshToken").toString())
                .endpoint(MyConfig.getAmazonLwaEndpoint())
                .build();

        FbaInboundApi api = new FbaInboundApi.Builder()
                .lwaAuthorizationCredentials(lwaAuthorizationCredentials)
                .endpoint(jsonObject.get("amazonServiceUrl").toString())
                .build();
        try {
//            ListInboundPlanItemsResponse listInboundPlanBoxesResponse1 = api.listInboundPlanItems(
//                    "wf294daf74-8d88-4bf9-a61f-73cb89da741b", null, null);
            ListShipmentBoxesResponse listInboundPlanBoxesResponse = api.listShipmentBoxes(
                    "wf294daf74-8d88-4bf9-a61f-73cb89da741b","sh4d94d23c-72c0-4e01-8aae-a1b019a41375", null, null);
            listInboundPlanBoxesResponse = listInboundPlanBoxesResponse;
            System.out.println("listInboundPlanBoxesResponse=" + listInboundPlanBoxesResponse);

        } catch (ApiException e) {
            System.out.println("ApiException = " + e.getResponseBody());
            e.printStackTrace();
        } catch (LWAException e) {
            e.printStackTrace();
        }

    }

    private R getInboundOperationStatusList(String operationId,String pid,String id,FbaInboundApi fbaInboundApi){
        try {
            boolean bool = true;
            long millis = 1000L;
            while (bool){
                InboundOperationStatus inboundOperationStatus = fbaInboundApi.getInboundOperationStatus(operationId);
                if (inboundOperationStatus.getOperationStatus().getValue().equals(OperationStatus.FAILED.getValue())){
                    return R.error(inboundOperationStatus.getOperationProblems().get(0).getMessage());
                }
                if (inboundOperationStatus.getOperationStatus().getValue().equals(OperationStatus.SUCCESS.getValue())){
                    bool = false;
                    return R.ok();
                }
                Thread.sleep(millis);
                millis += millis *2;
                if (millis > 27000L){
                    return R.error("请求亚马逊api等待超时,请联系管理员,或者稍等后再次操作!");
                }
            }
        } catch (ApiException e) {
            return R.error(e.getResponseBody());
        } catch (Exception e) {
            return R.error(e.getMessage());
        }
        return R.ok();
    }
}
